import { VantResolve, createStyleImportPlugin } from "vite-plugin-style-import";

export default function initAutoStyleImport() {
  const excludeStyle = ["show-confirm-dialog"];
  return createStyleImportPlugin({
    resolves: [VantResolve()],
    libs: [
      {
        libraryName: "vant",
        esModule: true,
        // 重写引入路径 由于自动检测组件依赖的css的路径是show-xxx 所以把前五个show-去掉
        resolveStyle: name => {
          // 需要过滤一些不存在的文件
          let names = name;
          if (names.substring(5, 0) === "show-") {
            names = excludeStyle.includes(name) ? "dialog" : name.substring(5);
          }
          return `../es/${names}/style`;
        }
      }
    ]
  });
}
